package app

import (
	"gin-app/app/common/request"
	"gin-app/app/common/response"
	"gin-app/app/services"
	"github.com/gin-gonic/gin"
)

// 新建零售负责人
func CreateRetailArea(c *gin.Context) {
	var form request.CreateRetailArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err, Area := services.WaterSourceService.CreateRetailArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}

// 获取零售负责人列表
func GetRetailAreaList(c *gin.Context) {
	if err, Area := services.WaterSourceService.GetRetailAreaList(); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}

// 删除零售负责人
func DeleteRetailArea(c *gin.Context) {
	var form request.DeleteRetailArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err := services.WaterSourceService.DeleteRetailArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, "OK")
	}
}

// 编辑零售负责人
func EditorRetailArea(c *gin.Context) {
	var form request.EditorRetailArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err, Area := services.WaterSourceService.EditorRetailArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}

// 新建水源负责人
func CreateWaterSourceArea(c *gin.Context) {
	var form request.CreateWaterSourceArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err, Area := services.WaterSourceService.CreateWaterSourceArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}

// 获取水源负责人列表
func GetWaterSourceAreaList(c *gin.Context) {
	if err, Area := services.WaterSourceService.GetWaterSourceAreaList(); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}

// 删除水源负责人
func DeleteWaterSourceArea(c *gin.Context) {
	var form request.DeleteWaterSourceArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err := services.WaterSourceService.DeleteWaterSourceArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, "OK")
	}
}

// 编辑水源负责人
func EditorWaterSourceArea(c *gin.Context) {
	var form request.EditorWaterSourceArea
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}
	if err, Area := services.WaterSourceService.EditorWaterSourceArea(form); err != nil {
		response.BusinessFail(c, err.Error())
	} else {
		response.Success(c, Area)
	}
}
